from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from pydantic import BaseModel

app = FastAPI()

# 数据库配置（替换为你的 MySQL 信息）
DATABASE_URL = "mysql+aiomysql://root:root@localhost:3306/movie_db"
engine = create_async_engine(DATABASE_URL)
AsyncSessionLocal = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

# 测试模型（示例）
class Movie(BaseModel):
    id: int
    title: str

# 测试接口
@app.get("/", response_model=dict)
async def root():
    return {"message": "FastAPI + MySQL 环境就绪（Python 3.14）"}

@app.get("/movies", response_model=list[Movie])
async def get_movies():
    async with AsyncSessionLocal() as session:
        # 实际项目中替换为真实查询
        return [{"id": 1, "title": "Test Movie"}]